home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS19.ADF / DiskLib / DiskLib.BAS (.txt) < prev    next >
AmigaBASIC Source Code  |  1989-01-27  |  8KB  |  328 lines

  1. REM disklib.bas by John Kennan 10-21-86
  2. CLEAR,20000
  3. CLEAR,50000,5000
  4. OPTION BASE 1
  5. DIM prog$(1500),dir$(400),prog%(1500)
  6. dircheck=0:dircount=0:progcount=0
  7. dname$=""
  8. DECLARE FUNCTION Execute& LIBRARY
  9. PRINT "For this program to work properly, Amigabasic must be started"
  10. PRINT "from the CLI!
  11. PRINT "If you have a one drive system, either boot on the DISKLIB:"
  12. PRINT "disk, or go to the CLI and type:"
  13. PRINT "`Execute Disklib:s/startup-sequence'"
  14. PRINT "If you have a two drive system, place Disklib: in the External Drive"
  15. PRINT "and use the internal drive to add disks to the library."
  16. WHILE ((drive<>1) AND (drive<>2))
  17. INPUT;"Are you working on a one or two drive system (1 or 2):";drive
  18. WEND
  19. CLS
  20. IF drive=1 THEN 
  21.   CHDIR "Ram:" 
  22.  ELSE 
  23.   CHDIR "disklib:"
  24.   LIBRARY "dos.library"
  25.   x=Execute&(SADD("Assign c: disklib:c"+CHR$(0)), 0, 0)
  26.   x=Execute&(SADD("Assign l: disklib:l"+CHR$(0)), 0, 0)
  27.   x=Execute&(SADD("Assign devs: disklib:devs"+CHR$(0)), 0, 0)
  28.   x=Execute&(SADD("Assign libs: disklib:libs"+CHR$(0)), 0, 0)
  29.   x=Execute&(SADD("CD disklib:"+CHR$(0)), 0, 0)
  30.   LIBRARY CLOSE
  31. END IF
  32. main:
  33.   CLS
  34.   PRINT "Library currently contains " progcount " programs (max 1500) and" 
  35.   PRINT dircount " directories (max 400)"
  36.   PRINT "You have " FRE(1) "bytes of free memory in Basic"
  37.   PRINT "Choose an option"
  38.   PRINT "1-Add a Disk"
  39.   PRINT "2-Sort by Directory"
  40.   PRINT "3-Sort by Program"
  41.   PRINT "4-Print Library to Screen"
  42.   PRINT "5-Print Library to Printer"
  43.   PRINT "6-Save Library to Disk"
  44.   PRINT "7-Load Library from Disk"
  45.   PRINT "8-Save Library as a Text File (for access from CLI)"
  46.   PRINT "9-Delete a Directory"
  47.   PRINT "10-Exit Program"
  48.   choice=-1
  49.   WHILE ((choice>10) OR (choice<1)) 
  50.   INPUT;"Enter option 1-10:";choice
  51.   WEND
  52.   ON choice GOSUB adddisk,shellsort1,shellsort2,scprint,pprint,fsave,fload,textsave,dirdelete,exprog
  53.   GOTO main
  54. adddisk:
  55.   PRINT "Insert Disk to be added into DF0: and press 'C' to continue or 'A' to abort"
  56.   a$=""
  57.   WHILE ((a$<>"C") AND (a$<>"A"))
  58.   a$=INKEY$
  59.   a$=UCASE$(a$)
  60.   WEND
  61. IF a$="A" THEN RETURN      
  62. CALL diskname(dname$)
  63. IF dname$="" THEN 
  64.   PRINT "NO DISK IN DRIVE!!"
  65.   GOTO adddisk
  66. END IF  
  67. dircheck=dircheck+1:dircount=dircount+1
  68. dir$(dircheck)=dname$+":"
  69. flag=0
  70. WHILE flag=0
  71.  CALL listram(dir$(dircheck))
  72.  OPEN "ram:temp" FOR INPUT AS #1
  73. WHILE NOT EOF(1)
  74.   LINE INPUT #1, temp$
  75.   IF (INSTR(temp$,"Directory")=0 AND INSTR(temp$," Dir ")) THEN 
  76.   IF (LEFT$(temp$,4)<>"Dir ") THEN
  77.   IF (LEFT$(temp$,7)<>"MakeDir") THEN
  78.    IF (INSTR(temp$,"directories")=0) THEN
  79.     dircount=dircount+1
  80.     position=INSTR(temp$,"   ")
  81.     newdir$=LEFT$(temp$,(position-1))
  82.     dir$(dircount)=dir$(dircheck)+newdir$+"/"
  83.     IF newdir$="c" THEN dircount=dircount-1
  84.     IF newdir$="Trashcan" THEN dircount=dircount-1 
  85.     IF newdir$="l" THEN dircount=dircount-1
  86.     IF newdir$="s" THEN dircount=dircount-1   
  87.     IF newdir$="libs" THEN dircount=dircount-1
  88.     IF newdir$="fonts" THEN dircount=dircount-1
  89.     IF newdir$="devs" THEN dircount=dircount-1 
  90.    END IF
  91.    END IF
  92.    END IF
  93.   ELSE
  94.    IF ((INSTR(temp$,"irectory")=0) AND (INSTR(temp$,"irectories")=0)) THEN
  95.    IF ((INSTR(temp$,"ile -")=0) AND (INSTR(temp$,"iles -")=0)) THEN
  96.    IF (INSTR(temp$,".info")=0) THEN
  97.     progcount=progcount+1
  98.     prog%(progcount)=dircheck
  99.     position=INSTR(temp$,"   ")
  100.     prog$(progcount)=LEFT$(temp$,(position-1))
  101.    END IF
  102.    END IF
  103.   END IF
  104.   END IF
  105.  WEND
  106.   CLOSE #1
  107.   KILL "ram:temp"
  108. PRINT "dircheck=" dircheck
  109. PRINT "dircount=" dircount
  110. dircheck=dircheck+1
  111. IF dircheck>dircount THEN flag=1
  112. WEND
  113. dircheck=dircount
  114.   LIBRARY CLOSE
  115. RETURN
  116. scprint:
  117.   n=1:m=0
  118.   WHILE n<= progcount
  119.   WHILE m<20
  120.   IF n<=progcount THEN PRINT prog$(n) TAB(30) dir$(prog%(n))
  121.   n=n+1:m=m+1
  122.   WEND
  123.   m=0
  124.   PRINT "To Continue hit 'C' (or 'A' to abort)"
  125.     a$=""
  126.     WHILE ((a$<>"C") AND (a$<>"A"))
  127.     a$=INKEY$
  128.     a$=UCASE$(a$)
  129.     WEND
  130.   IF a$="A" THEN n=progcount+1     
  131.   WEND
  132. RETURN
  133. pprint:
  134.   GOSUB setprt
  135.   FOR n=1 TO progcount
  136.   LPRINT prog$(n) TAB(30) dir$(prog%(n))
  137.   NEXT n
  138. RETURN
  139. textsave:  
  140.   PRINT "If you are using a one drive system"
  141.   PRINT "Filename must include the drive specifier (ie. DF0:)"
  142.   PRINT "or the disk NAME, or the file will be saved TO Ram:"
  143.   INPUT;"Input file name to be SAVED (enter 'A' to abort)";a$
  144.   a$=UCASE$(a$)
  145.   IF a$="A" THEN RETURN
  146.   b$=""
  147.   IF (drive=1) AND (INSTR(a$,CHR$(58))=0) THEN
  148.       PRINT "You did not include the drive or disk name!!"
  149.       INPUT;"Do you want to save to df0: or abort (S or A)?:";b$
  150.       b$=UCASE$(b$)
  151.       IF b$="S" THEN a$="df0:"+a$
  152.   END IF 
  153.   IF b$="A" THEN RETURN   
  154.   OPEN a$ FOR OUTPUT AS #1
  155.   FOR n=1 TO progcount
  156.   PRINT #1,prog$(n) "\\" dir$(prog%(n))
  157.   NEXT n
  158.   CLOSE #1
  159.   RETURN
  160. fsave:
  161.   PRINT "If you are using a one drive system"
  162.   PRINT "Filename must include the drive specifier (ie. DF0:)"
  163.   PRINT "or the disk NAME, or the file will be saved TO Ram:"
  164.   INPUT;"Input file name to be SAVED (enter 'A' to abort)";a$
  165.   a$=UCASE$(a$)
  166.   IF a$="A" THEN RETURN
  167.   b$=""
  168.   IF (drive=1) AND (INSTR(a$,CHR$(58))=0) THEN 
  169.       PRINT "You did not include the drive or disk name!!"
  170.       INPUT;"Do you want to save to df0: or abort (S or A)?:";b$
  171.       b$=UCASE$(b$)
  172.       IF b$="S" THEN a$="df0:"+a$
  173.   END IF 
  174.   IF b$="A" THEN RETURN   
  175.   OPEN a$ FOR OUTPUT AS #1
  176.   PRINT #1,dircount;progcount
  177.   FOR n=1 TO dircount
  178.   WRITE #1, dir$(n)
  179.   NEXT n
  180.   FOR n=1 TO progcount
  181.   WRITE #1,prog$(n),prog%(n)
  182.   NEXT n
  183.   CLOSE #1
  184.   RETURN
  185. fload:
  186.   ON ERROR GOTO 0
  187.   PRINT "Filename must include the drive specifier (ie. DF0:)"
  188.   PRINT "or the disk NAME, or the file will be loaded from Ram:"
  189.   INPUT;"Input file name to be LOADED (enter 'A' to abort)";a$
  190.   a$=UCASE$(a$)
  191.   IF a$="A" THEN RETURN
  192.   ON ERROR GOTO diskerror
  193.   OPEN a$ FOR INPUT AS #1
  194.   ON ERROR GOTO 0 
  195.   INPUT #1,dircount,progcount
  196.   FOR n=1 TO dircount
  197.   INPUT #1, dir$(n)
  198.   NEXT n
  199.   FOR n=1 TO progcount
  200.   INPUT #1,prog$(n),prog%(n)
  201.   NEXT n
  202.   dircheck=dircount
  203.   CLOSE #1
  204.   RETURN  
  205. diskerror:
  206.   PRINT "FILE NOT FOUND!!":PRINT
  207.   RESUME fload
  208. shellsort1:
  209.   PRINT "Sorting...."
  210.   s=2^INT(LOG(progcount)/LOG(2))
  211.   IF s<(progcount/2) THEN s=s*2
  212.  startsort:
  213.   s=INT(s/2)
  214.   IF s=0 THEN RETURN
  215.   FOR t=1 TO progcount-s
  216.     y=t
  217.    L1:  
  218.     w=y+s
  219.     IF UCASE$(dir$(prog%(y)))<=UCASE$(dir$(prog%(w))) THEN  GOTO Skip1
  220.       SWAP prog%(y),prog%(w)
  221.       SWAP prog$(y),prog$(w)
  222.       y=y-s
  223.      IF y>0 THEN GOTO L1: 
  224.   Skip1:  
  225.    NEXT t
  226.    GOTO startsort 
  227. shellsort2:
  228.   PRINT "Sorting..."
  229.   s=2^INT(LOG(progcount)/LOG(2))
  230.   IF s<(progcount/2) THEN s=s*2
  231.  startsort2:
  232.   s=INT(s/2)
  233.   IF s=0 THEN RETURN
  234.   FOR t=1 TO progcount-s
  235.     y=t
  236.   L2:
  237.     w=y+s
  238.     IF UCASE$(prog$(y))<=UCASE$(prog$(w)) THEN GOTO Skip2
  239.       SWAP prog%(y),prog%(w)
  240.       SWAP prog$(y),prog$(w)
  241.       y=y-s
  242.    IF y>0 THEN GOTO L2:
  243.   Skip2:    
  244.    NEXT t
  245.    GOTO startsort2 
  246. SUB listram(currentdir$) STATIC
  247.   LIBRARY "dos.library"
  248.   x=Execute&(SADD("list >RAM:temp "+CHR$(34)+currentdir$+CHR$(34)+CHR$(0)), 0, 0)
  249.   LIBRARY CLOSE
  250. END SUB
  251. SUB diskname (dname$) STATIC 
  252.   LIBRARY "dos.library"
  253.   x=Execute&(SADD("info >RAM:temp"+CHR$(0)), 0, 0)
  254.   OPEN "RAM:temp" FOR INPUT AS #1
  255.   position=0
  256.   WHILE position=0
  257.     LINE INPUT #1,a$
  258.     position=INSTR(a$,"Name")
  259.   WEND  
  260. string=0
  261.   WHILE string=0
  262.     LINE INPUT #1,a$
  263.     string=INSTR(a$,"DF0:")
  264.   WEND
  265.   IF INSTR(a$,"No disk present")<>0 THEN
  266.   dname$=""
  267.   ELSE
  268.   dname$=RIGHT$(a$,LEN(a$)-position+1)  
  269.   END IF
  270.   CLOSE #1
  271.   KILL "RAM:temp"
  272.   LIBRARY CLOSE
  273. END SUB
  274. setprt:
  275. OPEN "prt:" FOR OUTPUT AS #1
  276. PRINT #1,CHR$(27);"c";
  277. PRINT #1,CHR$(27);"[66t";
  278. PRINT #1,CHR$(27);"[12q";
  279. CLOSE #1
  280. RETURN
  281. dirdelete:
  282.   INPUT;"Input Directory name to be deleted (enter 'A' to abort)";dirdel$
  283.   dirdel$=UCASE$(dirdel$)
  284.   IF dirdel$="A" THEN RETURN
  285.   zz=dircount
  286.   FOR n=zz TO 1 STEP -1
  287.   IF INSTR(dir$(n),dirdel$)<>0 THEN GOSUB ddelete
  288.   NEXT n
  289.   dircheck=dircount
  290.   RETURN
  291. ddelete:  
  292.   PRINT "Delete" dir$(n) "?(Y or N):":INPUT a$
  293.   a$=UCASE$(a$)
  294.   IF a$<>"Y" THEN RETURN
  295.   FOR m=n TO dircount-1
  296.   dir$(m)=dir$(m+1)
  297.   NEXT m
  298.   dircount=dircount-1
  299.   m=1
  300.   WHILE m<=progcount
  301.   IF prog%(m)=n THEN
  302.     FOR z=m TO progcount-1
  303.     prog%(z)=prog%(z+1)
  304.     prog$(z)=prog$(z+1)
  305.     NEXT z
  306.     progcount=progcount-1
  307.   END IF
  308.   IF prog%(m)>n THEN prog%(m)=prog%(m)-1
  309.   IF prog%(m)<>n THEN m=m+1
  310.   WEND
  311. RETURN    
  312. exprog:
  313.   LIBRARY CLOSE
  314.   CLOSE #1
  315.   CHDIR "Disklib:"
  316.   IF drive=2 THEN
  317.     LIBRARY "dos.library"
  318.     x=Execute&(SADD("Assign c: sys:c"+CHR$(0)), 0, 0)
  319.     x=Execute&(SADD("Assign l: sys:l"+CHR$(0)), 0, 0)
  320.     x=Execute&(SADD("Assign devs: sys:devs"+CHR$(0)), 0, 0)
  321.     x=Execute&(SADD("Assign libs: sys:libs"+CHR$(0)), 0, 0)
  322.     LIBRARY CLOSE
  323.   ELSE 
  324.     PRINT "To restore system to its condition before you ran the program"
  325.     PRINT "Go to the CLI and type `Execute disklib:s/end-sequence'"
  326.   END IF
  327. END
  328.